package com.feifan.web.controller.oa;

import com.feifan.common.annotation.Log;
import com.feifan.common.core.controller.BaseController;
import com.feifan.common.core.domain.AjaxResult;
import com.feifan.common.core.page.TableDataInfo;
import com.feifan.common.enums.BusinessType;
import com.feifan.common.utils.poi.ExcelUtil;
import com.feifan.oa.domain.FlowCategoryDetail;
import com.feifan.oa.service.IFlowCategoryDetailService;
import com.feifan.oa.service.IFlowCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 具体流程Controller
 * @author 非凡
 * @date 2020-07-01
 */
@Controller
@RequestMapping("/oa/detail")
public class FlowCategoryDetailController extends BaseController {
    private String prefix = "oa/flow/detail";

    @Autowired
    private IFlowCategoryDetailService flowCategoryDetailService;

    @Autowired
    private IFlowCategoryService flowCategoryService;

    @RequiresPermissions("oa:detail:view")
    @GetMapping()
    public String detail(ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        return prefix + "/detail";
    }

    /**
     * 查询具体流程列表
     */
    @RequiresPermissions("oa:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FlowCategoryDetail flowCategoryDetail) {
        startPage();
        List<FlowCategoryDetail> list = flowCategoryDetailService.selectFlowCategoryDetailList(flowCategoryDetail);
        return getDataTable(list);
    }

    /**
     * 导出具体流程列表
     */
    @RequiresPermissions("oa:detail:export")
    @Log(title = "具体流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FlowCategoryDetail flowCategoryDetail) {
        List<FlowCategoryDetail> list = flowCategoryDetailService.selectFlowCategoryDetailList(flowCategoryDetail);
        ExcelUtil<FlowCategoryDetail> util = new ExcelUtil<FlowCategoryDetail>(FlowCategoryDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 新增具体流程
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存具体流程
     */
    @RequiresPermissions("oa:detail:add")
    @Log(title = "具体流程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FlowCategoryDetail flowCategoryDetail) {
        return toAjax(flowCategoryDetailService.insertFlowCategoryDetail(flowCategoryDetail));
    }

    /**
     * 修改具体流程
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("flowCategoryList", flowCategoryService.selectFlowCategoryList(null));
        mmap.put("flowCategoryDetail", flowCategoryDetailService.selectFlowCategoryDetailById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存具体流程
     */
    @RequiresPermissions("oa:detail:edit")
    @Log(title = "具体流程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FlowCategoryDetail flowCategoryDetail) {
        return toAjax(flowCategoryDetailService.updateFlowCategoryDetail(flowCategoryDetail));
    }

    /**
     * 删除具体流程
     */
    @RequiresPermissions("oa:detail:remove")
    @Log(title = "具体流程", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(flowCategoryDetailService.deleteFlowCategoryDetailByIds(ids));
    }
}
